<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   xmlns:pe="http://primefaces.org/ui"
   template="/WEB-INF/templates/business/buyer/template.xhtml">
   
   	<f:metadata>
	   	<f:viewParam name="bulletinId" value="#{bulletinHome3.id}"></f:viewParam>
	   	<f:event listener="#{bulletinHome3.initConversation()}" type="preRenderView"></f:event>
   	</f:metadata>
   	<ui:define name="buyer_head">
   		<style type="text/css">
   			.removeButton {
   				float: right;
   				margin-right: 20px;
   			}
   			.limlitOfTime{
   				 position: relative;
    			 top: -9px;
   			}
   		</style>
   		
   		
		
		
   		
   		<script type="text/javascript">
   			var way  = "";
   			$(document).ready(function(){
   				way = $("select[name$='bulletieWayOfChoose_input'] option:selected").val();
   				showOrHideComps(way);
   	   		});
			function showOrHideComps(way){
				if(way  == 'Manual'){
					PF('save').jq.hide();
					PF('showManual').jq.show();
					document.getElementById("editForm:bulletinEndingApplyTime").style.display = 'none';
					document.getElementById("editForm:bulletinEndingApplyTimeLabel").style.display = 'none';
					document.getElementById("editForm:bulletinChooseTime").style.display = 'none';
					document.getElementById("editForm:bulletinChooseTimeLabel").style.display = 'none';
					
				}
				else {
					PF('save').jq.show();
					PF('showManual').jq.hide();
					document.getElementById("editForm:bulletinEndingApplyTime").style.display = 'block';
					document.getElementById("editForm:bulletinEndingApplyTimeLabel").style.display = 'block';
					document.getElementById("editForm:bulletinChooseTime").style.display = 'block';
					document.getElementById("editForm:bulletinChooseTimeLabel").style.display = 'block';
				}
			}
			function wayOfChooseChange(){
				way = $("select[name$='bulletieWayOfChoose_input'] option:selected").val();
				showOrHideComps(way);
				setDefaultCalendar(way);

				}
			function setDefaultCalendar(){
				if(way  == 'Manual'){
					PF('bulletinEndingApplyTime').setDate(new Date());
					PF('bulletinChooseTime').setDate(new Date());
				}else{
					PF('bulletinEndingApplyTime').setDate( null);
					PF('bulletinChooseTime').setDate(null);
				}
			}
		</script>
   	</ui:define>
   	<ui:define name="buyer_content">
   
		<h:form id="editForm"  >         
			<p:panel id="panel" header="发布公告" style="margin-bottom:10px;">
		        <p:messages id="messages" closable="true">
		       		<p:autoUpdate />
		       	</p:messages>	
		        <h:panelGrid columns="2" cellpadding="5">
					<ui:remove><p:outputLabel for="bulletinTitle" value="公告标题" />				
					<p:inputText id="bulletinTitle" value="#{bulletinHome3.instance.title}" styleClass="input-large" required="true" /></ui:remove>
					<p:outputLabel for="bulletinProjectName" value="采购项目名称" />				
					<p:inputText id="bulletinProjectName" value="#{bulletinHome3.instance.projectName}" styleClass="input-large"  required="true" />
					
					<p:outputLabel for="bulletinAmountOfInvestment" value="项目总投资（元）" />				
					<p:inputNumber id="bulletinAmountOfInvestment" minValue="0" value="#{bulletinHome3.instance.amountOfInvestment}"  required="true" />
					
					<p:outputLabel for="bulletinPrice" value="服务金额（元）" />				
					<p:inputText id="bulletinPrice" value="#{bulletinHome3.instance.servicePrice}"   required="true" />
					
					<p:outputLabel for="bulletinPriceRemark" value="服务金额说明" />				
					<p:inputTextarea rows="3" cols="50" id="bulletinPriceRemark"  value="#{bulletinHome3.instance.priceRemark}" />
					
					<p:outputLabel for="bulletinContent" value="服务内容" />				
					<p:inputText 	id="bulletinContent" value="#{bulletinHome3.instance.content}" styleClass="input-large" required="true" />
					
					<p:outputLabel for="bulletinProjectInfo" value="项目建设内容" />				
					<p:inputTextarea rows="3" cols="50" id="bulletinProjectInfo" value="#{bulletinHome3.instance.projectInfo}"  required="true" />
					
					
									
					
				 	<p:outputLabel for="bulletinLimitOfTime" value="合同约定完成时限" />	
					<p:outputPanel>	
						<p:inputMask id="bulletinLimitOfTime" styleClass="limlitOfTime"  maxlength="3" value="#{bulletinHome3.instance.limitOfTime}"  required="true" >
							<p:keyFilter regEx="/[\d\-]/" />
						</p:inputMask>
						<p:selectOneMenu id="bulletieWayLimitUnit" value="#{bulletinHome3.instance.limitUnit}"  styleClass="limitUnit"  required="true">						 	
						 	<f:selectItems value="#{enumUtils.getEnumArray('LimitUnit')}" var="_type" itemLabel="#{_type.typeName}" itemValue="#{_type}"></f:selectItems>
						</p:selectOneMenu>	
					</p:outputPanel>
					
					<p:outputLabel for="bulletinLimitRemark" value="合同约定完成时限说明" />				
					<p:inputTextarea rows="3" cols="50" id="bulletinLimitRemark" value="#{bulletinHome3.instance.limitRemark}"   />
					
					<p:outputLabel for="bulletinWayOfPayment" value="付款方式" />				
					<p:inputText id="bulletinWayOfPayment" value="#{bulletinHome3.instance.wayOfPayment}"  required="true" />
										
					<p:outputLabel for="bulletieWayOfChoose" value="选取方式" />		
					<p:selectOneMenu id="bulletieWayOfChoose" value="#{bulletinHome3.instance.wayOfChoose}" onchange="wayOfChooseChange()" required="true">
					 	<f:selectItem itemLabel="请选择" itemValue="#{null}"/>
					 	<f:selectItems value="#{enumUtils.getEnumArray('ChooseType')}" var="_type" itemLabel="#{_type.typeName}" itemValue="#{_type}"></f:selectItems>
					</p:selectOneMenu>	 	 
					
					<p:outputLabel for="bulletinEndingApplyTime"  id="bulletinEndingApplyTimeLabel" value="截止报名时间" />		
					<p:calendar  id="bulletinEndingApplyTime" widgetVar="bulletinEndingApplyTime" value="#{bulletinHome3.instance.endingApplyTime}" required="true"
						    pattern="yyyy-MM-dd HH:mm"
						     locale="zh_CN"
					inputStyleClass="input-middle"
							 showOn="button"
					  readonlyInput="true" />
					<p:outputLabel for="bulletinAddressOfChoose" value="公开选取中介地址" />				
					<p:inputText id="bulletinAddressOfChoose" value="#{bulletinHome3.instance.addressOfChoose}"  styleClass="input-large"  required="true" />
					
					<p:outputLabel for="bulletinChooseTime" id="bulletinChooseTimeLabel" value="开始选取时间" />		
					<p:calendar  id="bulletinChooseTime" widgetVar="bulletinChooseTime"  value="#{bulletinHome3.instance.chooseTime}" required="true"
						    pattern="yyyy-MM-dd HH:mm"
						     locale="zh_CN"
					inputStyleClass="input-middle"
							 showOn="button"
					  readonlyInput="true" />
					
					<ui:remove>
						<p:outputLabel for="bulletinOverTime" value="成交日期" />		
						<p:calendar  id="bulletinOverTime" widgetVar="bulletinOverTime"  value="#{bulletinHome3.instance.overTime}" required="true"
							    pattern="yyyy-MM-dd HH:mm"
							     locale="zh_CN"
						inputStyleClass="input-middle"
								 showOn="button"
						  readonlyInput="true" />
					</ui:remove>
					
					<p:outputLabel for="bulletinTeleOfConsult" value="咨询电话" />				
					<p:inputText id="bulletinTeleOfConsult" value="#{bulletinHome3.instance.teleOfConsult}"  required="true" />
					
					<p:outputLabel for="bulletinTeleOfSupervise" value="监督电话" />				
					<p:inputText id="bulletinTeleOfSupervise" value="#{bulletinHome3.instance.teleOfSupervise}"  required="true" />
					
				</h:panelGrid>
			</p:panel>
			<p:panel id="reqs" header="资质要求" style="margin-bottom:10px;">
		        <h:panelGrid columns="2" cellpadding="5">
		            <p:outputLabel for="qualificationClass" value="资质类别" />
		            <p:selectOneMenu id="qualificationClass" value="#{bulletinHome3.instance.qualificationTemplate.qualificationClass}"  immediate="true" required="true">
		                <f:selectItem itemLabel="请选择" itemValue="#{null}" />
		                <f:selectItems value="#{qualificationClassList.resultList}" var="_qc" itemLabel="#{_qc.name}" itemValue="#{_qc}" />
		                <f:converter converterId="entityConverter"></f:converter>
		                <p:ajax listener="#{bulletinHome3.clearSector()}" update=":editForm:sectorPanel :editForm:level" />
		            </p:selectOneMenu>
		            
		            <p:outputLabel for="sector" value="行业范围" />
		            <p:outputPanel id="sectorPanel">
		                <p:inputText id="sector" value="#{bulletinHome3.instance.qualificationTemplate.getSectorNames()}" styleClass="input-large" required="true" readonly="true" widgetVar="sector" />
		                <p:commandButton oncomplete="PF('chooseSectorDialog').show();" value="选择" immediate="true" update="chooseSectorDialog">
		                </p:commandButton>
		            </p:outputPanel>
		            
		            <p:outputLabel for="level" value="等级" />		            	
		            <p:selectOneMenu id="level" value="#{bulletinHome3.instance.qualificationTemplate.qualificationLevel}" required="true" widgetVar="level">
		                <f:selectItem itemLabel="请选择" itemValue="#{null}" />
		                <f:selectItems value="#{bulletinHome3.instance.qualificationTemplate.qualificationClass.sortedLevelOptions}" var="_lo" itemLabel="#{_lo.name}" itemValue="#{_lo}"></f:selectItems>
		                <f:converter converterId="entityConverter"></f:converter>
		            </p:selectOneMenu>
		            <p:outputLabel for="bulletinReqRemark" value="公告要求说明" />				
					<p:inputTextarea rows="3" cols="50" id="bulletinReqRemark" value="#{bulletinHome3.instance.reqRemark}"  />
		        </h:panelGrid>
			
			</p:panel>
			<p:commandButton widgetVar="save" action="#{bulletinHome3.saveAndFlush()}"  value="保存"  ajax="false" />
			<p:commandButton widgetVar="showManual" oncomplete="PF('chooseSuplierDialog').show();"  value="选择"   update="chooseSuplierDialog">
		    	<f:setPropertyActionListener value="#{bulletinHome3.instance.qualificationTemplate}"  target="#{supplierSelector.qualificationTemplate}"></f:setPropertyActionListener>
		    </p:commandButton>
			<p:commandButton action="#{bulletinHome3.delete()}" value="删除">
				<p:confirm header="请确认" message="您确认删除记录吗?" icon="ui-icon-alert" />
			</p:commandButton>
			<p:commandButton action="#{bulletinHome3.cancel()}" value="取消" immediate="true"></p:commandButton>	
		</h:form>
		
		<p:dialog id="chooseSectorDialog" 
		   widgetVar="chooseSectorDialog"
		   	   width="640"
		   	  height="480"
		   	   modal="true">
		   	<h:form id="sectotForm">
				<p:panel>
					<f:facet name="header">选择行业</f:facet>					
					<p:treeTable 
						value="#{bulletinHome3.rootNode}" 
						  var="_sectorNode"
						  selection="#{bulletinHome3.selectedNodes}"
					 rendered="#{not empty bulletinHome3.instance.qualificationTemplate.qualificationClass}"
				selectionMode="checkbox" >					
						<p:column>
							<f:facet name="header">行业类别</f:facet>
							#{_sectorNode.name}
						</p:column>
					</p:treeTable>
					
					<f:facet name="footer">
						<p:commandButton value="确定"  oncomplete="PF('chooseSectorDialog').hide();" action="#{bulletinHome3.chooseSectors()}" immediate="true" update=":editForm:sectorPanel" />
						<p:commandButton value="取消"  onclick="PF('chooseSectorDialog').hide();" />
					</f:facet>
				</p:panel>
				
			</h:form>			
		</p:dialog>
		
		<p:dialog id="chooseSuplierDialog" 
		   widgetVar="chooseSuplierDialog"
		   	   width="640"
		   	  height="480"
		   	   modal="true">
		   <h:form id="supplierForm">
				<p:panel rendered="#{not empty bulletinHome3.instance.qualificationTemplate}">
					<f:facet name="header">选择中介</f:facet>		
					<p:selectOneRadio id="suplierRadio" value="#{bulletinHome3.serviceSupplier}" layout="custom" >
						<f:selectItems value="#{supplierSelector.resultList}" var="_ss" itemLabel="#{_ss.cnname}" itemValue="#{_ss}"></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>
					</p:selectOneRadio>			
				<p:panelGrid style="width: 100%">
						<f:facet name="header">
							<p:row>
					            <p:column></p:column>
					            <p:column>
					            	<h:outputText value="中介名称" />
					            </p:column>
					            <p:column>
					            	<h:outputText value="地址" />
					            </p:column>
					        </p:row>	
						</f:facet>
						<c:forEach items="#{supplierSelector.resultList}" var="_suplier" varStatus="_status">
							<p:row>	
								<p:column style="width: 20px;">
									<p:radioButton for="suplierRadio" itemIndex="#{_status.index}" >
									</p:radioButton>
								</p:column>
								<p:column>
									<h:outputText value="#{_suplier.cnname}" />
								</p:column>
								<p:column >
									<h:outputText value="#{_suplier.address}" />
								</p:column>
							</p:row>					
						</c:forEach>
					</p:panelGrid>
					<ui:include src="/WEB-INF/templates/manage/pagination.xhtml">
						<ui:param name="entityList" value="#{supplierSelector}" />
					</ui:include>
					<f:facet name="footer">
						<p:commandButton value="保存" action="#{bulletinHome3.saveManual()}" />
						<p:commandButton value="取消" onclick="PF('chooseSuplierDialog').hide();" immediate="true"/>
					</f:facet>
				</p:panel>
			</h:form>			
		</p:dialog>
		
		
   	</ui:define>
</ui:composition>
